import 'package:flutter_jd/routes/routing_constants.dart';
import 'package:flutter_jd/service/global_service.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_jd/ui/widgets/kit.dart';
import 'package:get/route_manager.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

// 用户
class UserWrap extends GetWidget {
  @override
  Widget build(BuildContext context) {
    return Obx(() => _buildHead());
  }

  Widget _buildHead() {
    Widget userWidget = Container();
    GlobalConfigService globalService = Get.find();

    if (globalService.isLogin.value) {
      userWidget = GestureDetector(
        onTap: () {
          Get.toNamed(UserInfoRoute);
        },
        child: Container(
          color: Colors.transparent,
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 60.r,
                height: 60.r,
                decoration: BoxDecoration(
                  color: Color(0xFFF5F5F5),
                  borderRadius: BorderRadius.circular(60.r),
                ),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(60.r),
                  child: Image.asset(
                    'assets/images/common/avatar.png',
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              Expanded(
                child: Container(
                  height: 60.r,
                  margin: EdgeInsets.only(left: 15.w),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text(
                              '一颗希仔',
                              style: TextStyle(
                                fontSize: 15.sp,
                                fontWeight: FontWeight.w500,
                              ),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                            SizedBox(height: 3.h),
                            Text(
                              'jd_yikexizaifjsdkjsd',
                              style: TextStyle(
                                color: Color(0xFF888888),
                                fontSize: 12.sp,
                              ),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ],
                        ),
                      ),
                      Kit.iconFont(0xe7e7, Color(0xFF888888), 16.sp)
                    ],
                  ),
                ),
              )
            ],
          ),
        ),
      );
    } else {
      userWidget = GestureDetector(
        onTap: () {
          Get.toNamed(LoginRoute);
        },
        child: Container(
          color: Colors.transparent,
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                width: 50.r,
                height: 50.r,
                decoration: BoxDecoration(
                  color: Color(0xFFF2F2F2),
                  border: Border.all(
                    color: Colors.white,
                    width: 1.5.w,
                  ),
                  borderRadius: BorderRadius.circular(50.r),
                ),
              ),
              Expanded(
                child: Container(
                  margin: EdgeInsets.only(left: 15.w),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text(
                              '登录/注册',
                              style: TextStyle(
                                fontSize: 15.sp,
                                fontWeight: FontWeight.w500,
                              ),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ],
                        ),
                      ),
                      Kit.iconFont(0xe7e7, Color(0xFF888888), 16.sp)
                    ],
                  ),
                ),
              )
            ],
          ),
        ),
      );
    }

    return Container(
      padding: EdgeInsets.only(top: 20.h, left: 12.w, right: 12.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(
          bottomLeft: Radius.circular(10.r),
          bottomRight: Radius.circular(10.r),
        ),
      ),
      child: Column(
        children: [
          userWidget,
          GestureDetector(
            onTap: () {
              Get.toNamed(AddressManageRoute);
            },
            child: Container(
              height: 50.h,
              margin: EdgeInsets.only(top: 15.h),
              decoration: BoxDecoration(
                border: Border(
                  top: BorderSide(color: Color(0xFFF7F7F7)),
                ),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '地址管理',
                    style: TextStyle(fontSize: 15.sp),
                  ),
                  Kit.iconFont(0xe7e7, Color(0xFF888888), 14.sp)
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
